package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Tel        string `gorm:"type:varchar(20);not null"`
	Password   string `gorm:"type:varchar(32);not null"`
	HeadImage  string `gorm:"type:varchar(500);not null"`
	NickName   string `gorm:"type:varchar(30);not null"`
	Address    string `gorm:"type:varchar(30);not null"`
	WeChatCode string `gorm:"type:varchar(50);not null"`
	Qq         string `gorm:"type:varchar(50);not null"`
	Email      string `gorm:"type:varchar(50);not null"`
}

func (u *User) FindUserByTel(db *gorm.DB, tel string) error {
	return db.Debug().Where("tel=?", tel).Find(u).Error
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
